package com.hbfec.mqttmanager.mapper;

import com.hbfec.mqttmanager.entity.UserEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface UserMapper {
    @Select("SELECT username, is_superuser, created FROM mqtt_user")
    List<UserEntity> getAll();

    @Select("SELECT username, is_superuser, created FROM mqtt_user WHERE id = #{username}")
    UserEntity getOne(String username);

    @Insert("INSERT INTO mqtt_user(username,password,salt,is_superuser,created) VALUES(#{username}, #{password}, #{salt},#{is_superuser},#{created})")
    void insert(UserEntity user);

    @Update("UPDATE mqtt_user SET password=#{password} WHERE id =#{username}")
    void update(UserEntity user);

    @Delete("DELETE FROM mqtt_user WHERE id =#{username}")
    void delete(String username);
}
